package com.payment.web.controller.system;

import java.util.List;

import com.payment.common.annotation.Log;
import com.payment.common.base.AjaxResult;
import com.payment.common.enums.BusinessType;
import com.payment.common.page.TableDataInfo;
import com.payment.common.utils.ExcelUtil;
import com.payment.framework.web.base.BaseController;
import com.payment.system.domain.MerchantImage;
import com.payment.system.service.IMerchantImageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 商户资质 信息操作处理
 * 
 * @author payment
 * @date 2019-01-11
 */
@Controller
@RequestMapping("/system/merchantImage")
public class MerchantImageController extends BaseController
{
    private String prefix = "system/merchantImage";
	
	@Autowired
	private IMerchantImageService merchantImageService;
	
	@RequiresPermissions("system:merchantImage:view")
	@GetMapping()
	public String merchantImage()
	{
	    return prefix + "/merchantImage";
	}
	
	/**
	 * 查询商户资质列表
	 */
	@RequiresPermissions("system:merchantImage:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(MerchantImage merchantImage)
	{
		startPage();
        List<MerchantImage> list = merchantImageService.selectMerchantImageList(merchantImage);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出商户资质列表
	 */
	@RequiresPermissions("system:merchantImage:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerchantImage merchantImage)
    {
    	List<MerchantImage> list = merchantImageService.selectMerchantImageList(merchantImage);
        ExcelUtil<MerchantImage> util = new ExcelUtil<MerchantImage>(MerchantImage.class);
        return util.exportExcel(list, "merchantImage");
    }
	
	/**
	 * 新增商户资质
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存商户资质
	 */
	@RequiresPermissions("system:merchantImage:add")
	@Log(title = "商户资质", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(MerchantImage merchantImage)
	{		
		return toAjax(merchantImageService.insertMerchantImage(merchantImage));
	}

	/**
	 * 修改商户资质
	 */
	@GetMapping("/edit/{type}")
	public String edit(@PathVariable("type") String type, ModelMap mmap)
	{
		MerchantImage merchantImage = merchantImageService.selectMerchantImageById(type);
		mmap.put("merchantImage", merchantImage);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存商户资质
	 */
	@RequiresPermissions("system:merchantImage:edit")
	@Log(title = "商户资质", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(MerchantImage merchantImage)
	{		
		return toAjax(merchantImageService.updateMerchantImage(merchantImage));
	}
	
	/**
	 * 删除商户资质
	 */
	@RequiresPermissions("system:merchantImage:remove")
	@Log(title = "商户资质", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(merchantImageService.deleteMerchantImageByIds(ids));
	}
	
}
